import sys
import importer_v2 as importer
import datetime as datetime
import db
import baostock as bs

def load(sharding):
    clear_data = importer.load_sharding(sharding, None)
    print('load sharding')
    date_dic = importer.load_date(sharding)
    print('load date')
    if len(clear_data) > 0:
        bs.login()
        for data in clear_data:
            date = None
            if date_dic.__contains__(data["stock_code"]):
                date = date_dic[data["stock_code"]]
            importer.load_by_code(data["stock_code"], sharding, date, None, True)   
        bs.logout()
    print("分片:" + str(sharding) + "下载完成")
 

if __name__ == '__main__':
    args = ""
    if len(sys.argv) > 1:
        args = sys.argv[1]
    sharding = args
    load(sharding)

